package com.spell.joy.sdk;

import com.spell.joy.sdk.ad.JoyMaxReward;
import com.spell.joy.sdk.bridge.JoyCocosBridge;

import org.json.JSONObject;

public class JoyAdSdk implements JoySDKManager.JoyVideoCallback {
    private static JoyAdSdk wordAdSdk;
    private String ad_source = "";

    public static JoyAdSdk getInstance() {
        if (wordAdSdk == null) {
            wordAdSdk = new JoyAdSdk();
        }
        return wordAdSdk;
    }

    public void showAd(String ad_source) {
        showAd(ad_source, 8);
    }

    private static void adCallBack(String state, String ad_source) {
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("ad_source", ad_source);
            JoyCocosBridge.getInstance().XSSdkCallback(state, jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void showAd(String ad_source, int q) {
        this.ad_source=ad_source;
        showAd(this, q);
    }

    public static void showAd(JoySDKManager.JoyVideoCallback callback, int i) {
        try {
            JoyMaxReward.getInstance().showVideo(JoyCocosBridge.mainGameActivity.get(),callback);
        } catch (Exception e) {
            e.printStackTrace();
            callbackAdError(callback);
        }
    }


    private static void callbackAdError(JoySDKManager.JoyVideoCallback callback) {
        if (callback != null) {
            callback.onAdError();
        }
    }


    @Override
    public void onAdOver() {
        adCallBack("ad_over_joy", ad_source);
    }

    @Override
    public void onAdError() {
        adCallBack("ad_error_joy", ad_source);
    }



}
